import {getRestaurantInfo} from "@/common/api.js";

const state = {
	restaurantId: -1,
    restaurantInfo: {}
}
const mutations = {
//设置餐厅id
    SET_RESTAURANT_ID(state, id) {
        state.restaurantId = id
    },
    // 保存餐厅的信息
    SET_RESTAURANT_INFO(state, restaurantInfo) {
        state.restaurantInfo = restaurantInfo
    }
}
const actions = {
    setRestaurantId({commit}, id) {
        if(id===-1 || id===undefined || id===null){
            uni.showToast({
                title: '未找到该餐厅',
                icon: 'none',
                //显示持续时间为 2秒
                duration: 700
            })
            return
        }
        getRestaurantInfo(id).then(res => {
            if(res.message==='未找到该餐厅'){
                uni.showToast({
                    title: '未找到该餐厅',
                    icon: 'none',
                    //显示持续时间为 2秒
                    duration: 100
                })
                return
            }else {
                commit('SET_RESTAURANT_ID', id)
                commit('SET_RESTAURANT_INFO', res.data)
            }
        }).catch(err => {
            console.log(err)
        })
    }
}
const getters = {}
export default  {
	state,
	mutations,
	actions,
	getters
}
